﻿using System.Collections.Generic;
using System.Linq;

using Community.CsharpSqlite.SQLiteClient;

using VSTalk.Engine.Core.Data.Migration;

namespace VSTalk.Engine.Core.Data
{
    public class MigrationService : IMigrationService
    {
        private IList<IMigrationScript> _scripts;

        public MigrationService(IList<IMigrationScript> scripts)
        {
            _scripts = scripts;
        }

        public void Update(SqliteConnection connection, int currentVersion)
        {
            foreach (var script in _scripts.Skip(currentVersion))
            {
                script.Apply(connection);
            }
        }
    }
}